//
//  GDMStatusRetweetedView.swift
//  SinaWeibo
//
//  Created by mac on 15/12/2.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

import SnapKit

class GDMStatusRetweetedView: UIView {

    //    记录约束的属性
    var bottomConstraint : Constraint?
    
    var retweetedStatuses : GDMHomeStatusModel? {
        
        didSet {
            
            retweetedViewLabel.text = "@" + (retweetedStatuses?.user?.name ?? "") + ":" + (retweetedStatuses?.text ?? "")
            
            bottomConstraint?.uninstall()
    if let url = retweetedStatuses?.imageUrl where url.count != 0 {
                
                pictureView.imageURLs = url

                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                })

                pictureView.hidden = false
                
            }else {

                self.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.bottomConstraint = make.bottom.equalTo(retweetedViewLabel.snp_bottom).offset(StatusCellMargin).constraint
                })
                
                pictureView.hidden = true
            }

        }
    }
    
    //MARK: 重写构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK: 设置UI 及布局
    private func setupUI() {
        
        addSubview(retweetedViewLabel)
        
        addSubview(pictureView)
        
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(retweetedViewLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedViewLabel.snp_left)
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        
        retweetedViewLabel.snp_makeConstraints { (make) -> Void in
            
            make.left.top.equalTo(self).offset(StatusCellMargin)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            
           self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
        
//        设置一下背景颜色
//        backgroundColor = UIColor.randomColor()
        
    }
    
    private lazy var retweetedViewLabel : UILabel = UILabel(title: "等级划分的话费交电话费", color: UIColor.darkGrayColor(), fontSize: 14, margin: StatusCellMargin)
    private lazy var pictureView : GDMStatusPictView = GDMStatusPictView()

}
